package vip.meeet.concurrent;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class SuspendTest2 {
    
    static Object lock = new Object();
    
    public static void main(String[] args) {
        Suspend s1 = new Suspend();
        Suspend s2 = new Suspend();
        s1.start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LockSupport.unpark(s1);
        s2.start();
        LockSupport.unpark(s2);
        
    }
    
    static class Suspend extends Thread{
        @Override
        public void run() {
            synchronized(lock){
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                LockSupport.park();
            }
        }
    }

}
